﻿using System;
using System.ServiceModel.Syndication;
using System.Text;

namespace DataService.Model
{
    public class EngadgetSynItem:SyndicationItemBase
    {
        public EngadgetSynItem(SyndicationItem baseItem)
            : base(baseItem)
		{
		}
		protected override void ParseSummary(string summaryText)
		{
			int num = summaryText.IndexOf("<img");
			int num2 = summaryText.IndexOf("src=", num) + 5;
			int num3 = summaryText.IndexOf("\"", num2);
			base.ImageSrc = summaryText.Substring(num2, num3 - num2);//图片路径
			int num4;
			if (summaryText.StartsWith("<div"))
			{
				num4 = summaryText.IndexOf("/div", num3) + 5;
			}
			else
			{
				num4 = summaryText.IndexOf("/a", num3) + 3;
			}
			StringBuilder stringBuilder = new StringBuilder();
			bool flag = false;
			int i;
			for (i = num4; i < summaryText.Length - 1; i++)
			{
				if (summaryText[i] == '<')
				{
					flag = true;
					if (summaryText[i+1] == 'p')
					{
						break;
					}
				}
				else
				{
					if (summaryText[i] == '>')
					{
						flag = false;
					}
					else
					{
						if (!flag)
						{
							stringBuilder.Append(summaryText[i]);
						}
					}
				}
			}
			base.Description = base.DecodeString(stringBuilder.ToString());
			int num5 = summaryText.IndexOf("alt=\"source\"", i);
			if (num5 > 0)
			{
				num5 = summaryText.IndexOf("href", num5) + 6;
				int num6 = summaryText.IndexOf("\"", num5);
				base.SourceUrl = summaryText.Substring(num5, num6 - num5);
				num5 = num6 + 2;
				num6 = summaryText.IndexOf("</a>", num6);
				base.Source = summaryText.Substring(num5, num6 - num5);
			}
		}
    }
}
